package com.winspread.app.popspinner

import android.os.Bundle
import android.view.View
import com.winspread.active.extension.toast
import com.winspread.app.R
import com.winspread.app.databinding.ActivityPopSpinnerBinding
import com.winspread.mvvm.base.vm.BaseNotVmActivity
import com.winspread.ui.spinner.PopSpinnerView
import com.winspread.ui.utils.SizeUtils


class PopSpinnerViewActivity : BaseNotVmActivity<ActivityPopSpinnerBinding>(R.layout.activity_pop_spinner) {

    private var mFruitList: MutableList<Fruit>? = null

    override fun initView() {

    }

    override fun initData(extras: Bundle?) {
        mFruitList = ArrayList()
        for (i in 0..4) {
            mFruitList?.add(Fruit("苹果$i", 5))
            mFruitList?.add(Fruit("香蕉$i", 6))
            mFruitList?.add(Fruit("橘子$i", 7))
            mFruitList?.add(Fruit("火龙果$i", 8))
            mFruitList?.add(Fruit("西瓜$i", 9))
            mFruitList?.add(Fruit("猕猴桃$i", 10))
            mFruitList?.add(Fruit("芒果$i", 11))
            mFruitList?.add(Fruit("猕猴桃$i", 12))
        }
        binding.popSpinnerView.init(mFruitList!!.size, SizeUtils.dp2px(180f), object : PopSpinnerView.NameFilter {
            override fun filter(position: Int): String? {
                return mFruitList!!.get(position).getName()
            }
        })
    }

    override fun initListenter() {
        binding.popSpinnerBut.setOnClickListener(object : View.OnClickListener{
            override fun onClick(v: View?) {
                val selectIndex: Int = binding.popSpinnerView.getSelectIndex()
                if (selectIndex == -1) {
                    "请先选择水果".toast()
                    return
                }
                val fruit = mFruitList!![selectIndex]
                "${fruit.toString()}".toast()
            }
        })

    }

}